package com.wisdytech.linkdcs.tool.service.impl;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.handler.BaseService;
import com.wisdytech.linkdcs.tool.dao.ToolReplaceRecordDao;
import com.wisdytech.linkdcs.tool.model.ToolReplaceRecord;
import com.wisdytech.linkdcs.tool.service.IToolReplaceRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-11
 */
@Service
@Transactional
public class ToolReplaceRecordServiceImpl extends BaseService<ToolReplaceRecordDao, ToolReplaceRecord> implements IToolReplaceRecordService {

    @Override
    public PageInfo<ToolReplaceRecord> getToolReplaceRecordByFilter(String equipCode, String equipName, String toolCode, String toolName, String replaceDateStart, String replaceDateEnd, Filter filter) {
        Map<String, Object> params = new HashMap<>();
        if(StringUtils.isNotBlank(equipCode)) {
            params.put("equipCode",equipCode);
        }
        if(StringUtils.isNotBlank(equipName)) {
            params.put("equipName",equipName);
        }
        if(StringUtils.isNotBlank(toolCode)) {
            params.put("toolCode",toolCode);
        }
        if(StringUtils.isNotBlank(toolName)) {
            params.put("toolName",toolName);
        }
        if(StringUtils.isNotBlank(replaceDateStart)) {
            params.put("replaceDateStart",replaceDateStart);
        }
        if(StringUtils.isNotBlank(replaceDateEnd)) {
            params.put("replaceDateEnd",replaceDateEnd);
        }
        List<ToolReplaceRecord> list = this.beforeList(ToolReplaceRecordDao.class, filter).getToolReplaceRecordByFilter(params);
        PageInfo<ToolReplaceRecord> page = new PageInfo<>(list);
        return page;

    }
}
